#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int mod=998244353,inf=0x3f3f3f3f3f3f3f3f;
const int N=1e6+10,M=2e5+10;
mt19937 rnd(time(0));
int ch[N][2],id[N],cnt[N],ans,tot=1,dep[N];
struct info{
	int fi,se;
	bool operator <(info y)const{
		return fi+2-se>y.fi+2-y.se;
	}
};
priority_queue<info>pq[N];
int n;
string s[N];
void insert(string &s)
{
	int x=1;
	for ( auto c:s )
	{
		int op=c-'0';
		if(!ch[x][op])
		{
			ch[x][op]=++tot;
			dep[tot]=dep[x]+1;
		}
		x=ch[x][op];
	}
	cnt[x]++;
//	cerr << s <<" " << x << endl;
}
void dfs(int x)
{
	int ls=ch[x][0],rs=ch[x][1];
	if(ls+rs==0)
	{
		id[x]=x;
		pq[id[x]].push({dep[x],0});
//		cerr << "debug\n";
//		auto q=pq[id[x]];
//		while(!q.empty())
//		{
//			cerr << q.top().fi << " " << q.top().se << endl;
//			q.pop();
//		}
		cnt[x]--;
		while(cnt[x]--)
		{
			auto tp=pq[id[x]].top();pq[id[x]].pop();
//			cerr << "pop\n";
			ans+=tp.fi+2-tp.se-dep[x];
			pq[id[x]].push({tp.fi+1,0});
			if(!tp.se)pq[id[x]].push({tp.fi+1,0});
//			cerr << "ps\nps\n";
		}
//		cerr << "debug\n";
//		q=pq[id[x]];
//		while(!q.empty())
//		{
//			cerr << q.top().fi << " " << q.top().se << endl;
//			q.pop();
//		}
	}else if(!ls)
	{
		dfs(rs);
//		cerr << "d " << x << "\n";
		id[x]=id[rs];
		pq[id[x]].push({dep[x],1});
//		cerr << "d " << x << "\n";
		while(cnt[x]--)
		{
//			cerr << cnt[x] << endl;
			auto tp=pq[id[x]].top();pq[id[x]].pop();
			ans+=tp.fi+2-tp.se-dep[x];
			pq[id[x]].push({tp.fi+1,0});
			if(!tp.se)pq[id[x]].push({tp.fi+1,0});
		}
//		cerr << ans << endl;
//		cerr << "d " << x << "\n";
	}else if(!rs)
	{
		dfs(ls);
		id[x]=id[ls];
		pq[id[x]].push({dep[x],1});
		while(cnt[x]--)
		{
			auto tp=pq[id[x]].top();pq[id[x]].pop();
			ans+=tp.fi+2-tp.se-dep[x];
			pq[id[x]].push({tp.fi+1,0});
			if(!tp.se)pq[id[x]].push({tp.fi+1,0});
		}
	}else{
		dfs(ls),dfs(rs);
		if(pq[id[ls]].size()>pq[id[rs]].size())
		{
			id[x]=id[ls];
			while(!pq[id[rs]].empty())
			{
				pq[id[ls]].push(pq[id[rs]].top());
				pq[id[rs]].pop();
			}
		}else{
			id[x]=id[rs];
			while(!pq[id[ls]].empty())
			{
				pq[id[rs]].push(pq[id[ls]].top());
				pq[id[ls]].pop();
			}
		}
		while(cnt[x]--)
		{
			auto tp=pq[id[x]].top();pq[id[x]].pop();
			ans+=tp.fi+2-tp.se-dep[x];
			pq[id[x]].push({tp.fi+1,0});
			if(!tp.se)pq[id[x]].push({tp.fi+1,0});
		}
	}
//	cerr << x << endl;
}
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	freopen("id.in","r",stdin);
	freopen("id.out","w",stdout);
	cin >> n;
	for ( int i = 1 ; i <= n ; i++ )cin >> s[i];
	for ( int i = 1 ; i <= n ; i++ )insert(s[i]);
	dfs(1);
	cout << ans;
	return 0;
}


